#ifndef _MOE_RANDOM_
#define _MOE_RANDOM_
#include <stdlib.h>

class Random {

private:

    static Random* instance;

    static const int SIZE =55;
    static const double DEFINITION = 1e-10;

    double *values;
    int actual;


    Random(double seed) {
        init(seed);
    }

    Random(){
    }

public:

    ~Random() {
        delete[] values;
    }

    static Random *getInstance() {

        if (instance == NULL)
            instance = new Random();

        return instance;
    }

    static void shutdown() {
        if (instance != NULL) delete instance;
    }

    /** probability from true*/
    bool flip(double probability) {

        double r = getReal(0.0, 1.0);

        if (r < probability)
            return true;

        else
            return false;

    }

    void seed(double seed) {
        init(seed);
    }

    int getInt(int module) {
        return getInt(0, module);
    }

    int getInt(int min, int max) {
        return (int)(random() * (max - min)) + min;
    }

    float getFloat(float min, float max) {
        return random() * (max - min) + min;
    }


    double getReal(double min, double max) {
        return random() * (max - min) + min;
    }


private:

    void init(double seed);

    void warmup(double seed);

    void advance();

    /**@return a random value between 0.0 and 1.0*/
    double random();
};

#endif
